<?php

namespace yiike\company\model;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yiike\company\model\StoreOrder;

/**
* StoreOrderSearch represents the model behind the search form about `yiike\company\model\StoreOrder`.
*/
class StoreOrderSearch extends StoreOrder
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'weid', 'uid', 'store_id', 'table_id', 'type',  'reward_credit', 'consumer_code', 'is_pay', 'is_refund', 'status', 'created_at', 'maker_id', 'company_id', 'member_store_id', 'sent_at'], 'integer'],
            [['store_title', 'table_name', 'trade_id', 'uniontid', 'nickname', 'memo',], 'safe'],
            [[ 'no_discount',  'settlement', 'service_fee', 'refund_amount'], 'number'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = StoreOrder::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'weid' => $this->weid,
            'uid' => $this->uid,
            'store_id' => $this->store_id,
            'table_id' => $this->table_id,
            'type' => $this->type,
            'date' => $this->date,
            'total' => $this->total,
            'no_discount' => $this->no_discount,
            'commision' => $this->commision,
            'coupon' => $this->coupon,
            'real_pay' => $this->real_pay,
            'settlement' => $this->settlement,
            'reward_credit' => $this->reward_credit,
            'service_fee' => $this->service_fee,
            'consumer_code' => $this->consumer_code,
            'refund_amount' => $this->refund_amount,
            'is_pay' => $this->is_pay,
            'is_refund' => $this->is_refund,
            'status' => $this->status,
            'created_at' => $this->created_at,
            'pay_at' => $this->pay_at,
            'maker_id' => $this->maker_id,
            'company_id' => $this->company_id,
            'member_store_id' => $this->member_store_id,
            'sent_at' => $this->sent_at,
        ]);

        $query->andFilterWhere(['like', 'store_title', $this->store_title])
            ->andFilterWhere(['like', 'table_name', $this->table_name])
            ->andFilterWhere(['like', 'trade_id', $this->trade_id])
            ->andFilterWhere(['like', 'uniontid', $this->uniontid])
            ->andFilterWhere(['like', 'nickname', $this->nickname])
            ->andFilterWhere(['like', 'memo', $this->memo]);

return $dataProvider;
}
}